var LOGGING            = true;
var USE_LOG4JAVASCRIPT = false;
var USE_CONSOLE_ONLY   = false;

var logger4javascript;

function log_init(){
	if(LOGGING) {
		if(!USE_CONSOLE_ONLY && (!window.console || USE_LOG4JAVASCRIPT)) {
			logger4javascript = log4javascript.getDefaultLogger();
		}	
	}
}

var LOG = {};

LOG.TRACE = 1;
LOG.DEBUG = 2;
LOG.INFO  = 3;
LOG.WARN  = 4;
LOG.ERROR = 5;
LOG.FATAL = 6;

function log(msg, obj_level, level){
	if(LOGGING) {
		if(window.console && (!USE_LOG4JAVASCRIPT || USE_CONSOLE_ONLY)){
			console.log(msg);
		} else {
			if(!USE_CONSOLE_ONLY) {
				if(typeof msg == 'object') {
					obj_level = (obj_level == undefined) ? 3 : obj_level; 
					msg = var_dump(msg,{maxlevel:obj_level,noFunc:true});
				}
	
				if(level == undefined)
					logger4javascript.debug(msg);
				else {
					switch(level) {
						case LOG.TRACE: logger4javascript.trace(msg); break;
						case LOG.DEBUG: logger4javascript.debug(msg); break;
						case LOG.INFO : logger4javascript.info (msg); break;
						case LOG.WARN : logger4javascript.warn (msg); break;
						case LOG.ERROR: logger4javascript.error(msg); break;
						case LOG.FATAL: logger4javascript.fatal(msg); break;
						default       : logger4javascript.debug(msg); break;
					}
				}
			}
		}
	}
}

log_init();
